var app = getApp(),
  $ = require("../../utils/httpHelper.js")
Page({
  data: {
    addr:'',
    height: 0,
    nomore: true,
    add:true,
    ischoose:false,
    good_id:'',
    good_num:'',
    froma:''
  },
  onLoad: function (options) {
    var self = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        self.setData({ height: res.windowHeight-50 })
      }
    })
    this.getdata()

    //来自订单
    if(!app.check_empty(options.from)){
      console.log(options)
      this.setData({
        ischoose:true
      })
      //来自购物车订单
      if(options.from == 'car'){
        this.setData({
          froma:'car'
        })
      } else if (options.from == 'obl'){
        //来自待付款订单
        this.setData({
          froma:'obl',
          good_id: options.good_id,
          good_num: options.num
        })
      }
    }else{
      this.setData({
        ischoose:false
      })
    }
  },
  getdata(){
    let params = {
      rd_session: app.globalData.userInfo.rd_session,
    }
    $.httpPost("address_list", params, (data, err) => {
      this.setData({
        addr: data.lists
      })
    })
  },
  select(e){
    let id = e.target.dataset.id
    
    if(this.data.froma == 'car'){
      wx.redirectTo({
        url: '/pages/obligation/obligation?from=addr&status=car&addr_id='+id,
      })
    }else{
      let das = '&good_id='+this.data.good_id+"&num="+this.data.good_num
      console.log(das)
      wx.redirectTo({
        url: '/pages/obligation/obligation?from=addr&status=obl&addr_id='+id+das,
      })
    }
  },
  checkboxChange: function (e) {
    console.log('checkbox发生change事件，携带value值为：', e.detail.value)
  },
  delect(e){
    let id = e.target.dataset.id
    let that = this
    wx.showModal({
      title: '删除',
      content: '确定要删除该地址吗？',
      confirmColor: "#AD8556",
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
          let params = {
            rd_session: app.globalData.userInfo.rd_session,
            address_id: id
          }
          $.httpPost('delete_address', params, (data, err) => {
            if (data.result == "success") {
              wx.showToast({
                title: data.message,
              })
              that.getdata()
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  newadr(){
    wx.redirectTo({
      url: '/pages/address/address',
    })
  },
  editadr(e){
    let id = e.currentTarget.dataset.id
    wx.redirectTo({
      url: '/pages/address/address?address_id=' + id,
    })
  }
  
    
})  